package com.boarsoft.boar.batch.demo.flow.bigfile;

import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.boarsoft.flow.core.bean.ForkHandler;

/**
 * @ClassName:  QryDpfm01Fork   
 * @Description:ForkHandler决定后面fork的线程数，以及给后面fork的线程传递数据
 * @author: 
 * @date:   2019年2月15日 上午9:50:59   
 * @Copyright: 2019
 */
public class QryDpfm02Fork implements ForkHandler {
	private static final Logger log = LoggerFactory.getLogger(QryDpfm02Fork.class);
	
	public static long qryDpfm02ForkStart;
	
	@SuppressWarnings("unchecked")
	@Override
	public Map<String, Object> fork(String key, Object data, Throwable throwable) {
		
		qryDpfm02ForkStart = System.currentTimeMillis();
		
		Map<String, Object> pm = (Map<String, Object>) data;
		String hql = (String) pm.get("select");
		int tenantCount = (int) pm.get("tenantCount");

		System.out.println("租户数：" + tenantCount);
		System.out.println("hql：" + hql);
		
		Map<String, Object> returnMap = new HashMap<String, Object>();
		for (int p = 0; p < tenantCount; p++) {
			Map<String, Object> map = new HashMap<String, Object>();
			map.putAll(pm);
			map.put("tenantId", p);
			returnMap.put("p".concat(String.valueOf(p)), map);
		}
//		for (String str:returnMap.keySet()) {
//			Map<String, Object> valueMap = (Map<String, Object>) returnMap.get(str);
//			log.info("ForkHandler返回key: " + str + "  value: " + valueMap);
//		}
		
		System.out.println("开始分线程查询dpfm02数据...");
		return returnMap;
	}
}
